import 'package:flutter/material.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  static const Size loupeSize = Size(200, 200);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: RawMagnifierPage(),
    );
  }
}


class RawMagnifierPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return RawMagnifierPageState();
  }
}

class RawMagnifierPageState extends State {

  Offset dragGesturePositon = Offset.zero;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[200],
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('手指按下 放大显示'),
            Container(
              color: Colors.white,
              width: 300,
              height: 400,
              child: RepaintBoundary(
                child: buildStack(),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Stack buildStack() {
    return Stack(
      children: <Widget>[
        GestureDetector(
          onTapDown: (TapDownDetails details) {
            setState(() {
              dragGesturePositon = details.localPosition;
            });
          },
          onTapUp: (TapUpDetails details) {
            setState(() {
              dragGesturePositon = Offset.zero;
            });
          },
          onPanUpdate: (DragUpdateDetails details) {
            setState(
                  () {
                dragGesturePositon = details.localPosition;
              },
            );
          },
          child: const Text(
              "早起的年轻人 每天、每周，都会留下一些脚印，有一种执着，就是不知为什么，如果你迷茫，不妨来瞅瞅码农的轨迹"),
        ),
        buildDragGestureWidget(),
      ],
    );
  }

  buildDragGestureTipsWidget() {
    if (dragGesturePositon == Offset.zero) {
      return SizedBox();
    }
    return Positioned(
      left: dragGesturePositon.dx,
      top: dragGesturePositon.dy,
      child: Container(
        width: 10,
        height: 20,
        color: Colors.blue,
      ),
    );
  }

  buildDragGestureWidget() {
    if (dragGesturePositon == Offset.zero) {
      return SizedBox();
    }
    return Positioned(
      left: dragGesturePositon.dx,
      top: dragGesturePositon.dy,
      child: const RawMagnifier(
        decoration: MagnifierDecoration(
          shape: CircleBorder(
            side: BorderSide(color: Colors.pink, width: 3),
          ),
        ),
        size: Size(100, 100),
        magnificationScale: 2,
      ),
    );
  }
}

